#!/usr/bin/make -f
# -*- makefile -*-

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --with gir --no-parallel

DPKG_GENSYMBOLS_CHECK_LEVEL=4
export DPKG_GENSYMBOLS_CHECK_LEVEL

ifeq (linux,$(DEB_HOST_ARCH_OS))
  SYSTEMD_CONFIG_FLAG = --enable-systemd
else
  SYSTEMD_CONFIG_FLAG = --disable-systemd
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-gtk-doc \
		--enable-man-pages \
		--enable-introspection \
		$(SYSTEMD_CONFIG_FLAG) \
		--disable-examples \
		--libexecdir=\$${prefix}/lib/policykit-1

override_dh_auto_test:
	# on buildds we can't rely on actually having a system bus
	dbus-run-session -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$$DBUS_SESSION_BUS_ADDRESS make check'

override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/$(DEB_HOST_MULTIARCH)/polkit-1/

override_dh_install-arch:
	dh_install -a
	# on Debian use sudo group; on Ubuntu, also allow the admin group for
	# historical reasons
	if dpkg-vendor --is ubuntu; then \
	    /bin/echo -e "[Configuration]\nAdminIdentities=unix-group:sudo;unix-group:admin" > debian/policykit-1/etc/polkit-1/localauthority.conf.d/51-ubuntu-admin.conf; \
	elif dpkg-vendor --is debian; then \
	    /bin/echo -e "[Configuration]\nAdminIdentities=unix-group:sudo" > debian/policykit-1/etc/polkit-1/localauthority.conf.d/51-debian-sudo.conf; \
	fi
